#include "ServerDatabase.h"
#include <sstream>


using namespace std;

bool ServerDatabase::contains(std::string filename)
{
    for(unsigned int i = 0; i < data.size(); ++i)
    {
        if(data[i].filename == filename)
            return true;
    }
    return false;
}

FileInfo& ServerDatabase::get(std::string filename)
{
    for(unsigned int i = 0; i < data.size(); ++i)
    {
        if(data[i].filename == filename)
            return data[i];
    }
}

void ServerDatabase::add(FileInfo f)
{
    data.push_back(f);
}


std::string ServerDatabase::getFileList()
{
    stringstream ss;
    for(unsigned int i = 0; i < data.size(); ++i)
    {
        ss << data[i].toFileList() << '\n';
    }
    return ss.str();
}
